package com.tairanchina.md.meeting.service.impl;

import com.alibaba.dubbo.common.logger.Logger;
import com.alibaba.dubbo.common.logger.LoggerFactory;
import com.tairanchina.md.meeting.dao.YearMeetingAwardgoodsMapperExt;
import com.tairanchina.md.meeting.entity.YearMeetingAwardgoods;
import com.tairanchina.md.meeting.entity.YearMeetingAwardgoodsExample;
import com.tairanchina.md.meeting.service.YearMeetingAwardGoodsService;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by lxliuxuan on 2016/12/24.
 */
@Transactional
@Service
public class YearMeetingAwardGoodsServiceImpl implements YearMeetingAwardGoodsService {

	Logger logger = LoggerFactory.getLogger(YearMeetingAwardGoodsServiceImpl.class);
	
	@Resource
	private YearMeetingAwardgoodsMapperExt yearMeetingAwardGoods;

	@Override
	public List<YearMeetingAwardgoods> allPrizes() {
		YearMeetingAwardgoodsExample example = new YearMeetingAwardgoodsExample();
		List<YearMeetingAwardgoods> list = new ArrayList<>();
		try {
			list = yearMeetingAwardGoods.selectByExample(example);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("查询年会所有奖品信息异常", e);
		}
		
		return list;
	}

	@Override
	public YearMeetingAwardgoods findGoodsByLevel(Integer prizeLevel) {

		YearMeetingAwardgoodsExample example = new YearMeetingAwardgoodsExample();
		List<YearMeetingAwardgoods> list = new ArrayList<>();
		try {
			example.createCriteria().andAwardLevelEqualTo(prizeLevel);
			list = yearMeetingAwardGoods.selectByExample(example);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("查询年会奖品信息异常", e);
		}
		return list.get(0);
	}

	@Override
	public int updateGoodsByIdForNum(YearMeetingAwardgoods goods) {
		int res = 0;
		try {
			res = yearMeetingAwardGoods.updateByPrimaryKeySelective(goods);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("查询年会所有奖品信息异常", e);
		}
		return res;
	}

	@Override
	public List<YearMeetingAwardgoods> allPrizesByLevel(Integer awardLevel) {
		YearMeetingAwardgoodsExample example = new YearMeetingAwardgoodsExample();
		if(awardLevel != null){
			example.createCriteria().andAwardLevelEqualTo(awardLevel);
		}
		List<YearMeetingAwardgoods> list = new ArrayList<>();
		try {
			list = yearMeetingAwardGoods.selectByExample(example);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("查询年会所有奖品信息异常", e);
		}

		return list;
	}
}
